Skip to content

Conversation

@isoos
Copy link
Collaborator

@isoos isoos commented Nov 28, 2025

@isoos isoos force-pushed the task-loop-delete-instances branch 2 times, most recently from e0e8250 to 3de24fd Compare December 2, 2025 13:38
@isoos isoos requested a review from jonasfj December 2, 2025 13:38
@isoos
Copy link
Collaborator Author

isoos commented Dec 2, 2025

PTAL: I've updated the code as we've discussed - removed the events, fixed the logic (old test pass), and using a full list of instances.

@isoos isoos force-pushed the task-loop-delete-instances branch from 3de24fd to 135b26b Compare December 3, 2025 08:38

return DeleteInstancesNextState(
state: DeleteInstancesState(deletions: deletionInProgress),
deletionsDone: futures.isEmpty ? Future.value() : Future.wait(futures),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this...

I think that in testing we could either do:

await Future.delayed(microseconds: 10);

Instead of waiting for deletionsDone.


Or we could change the tests to wait for deleteInstanceFn to have been called N times.


Or we could await deleteInstanceFn in here, with some short timeout like 30s and if it has happened then we log a warning. Nor sure this necessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we could make the agreement that deleteInstanceFn invocations will have been started before we return from scanAndDeleteInstances.

But we won't have awaited the futures from deleteInstanceFn invocations.

That way, if deleteInstanceFn does anything sync, the sync thing will have run.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, scanAndDeleteInstances could return ({DeleteInstancesState nextState, Future<void> done}).

I don't like having a type for this... I don't know why.

It feels like we're letting internals escape.


I think we should make the promise that deleteInstanceFn will not be invoked after the Future from scanAndDeleteInstances has been resolved.

We're not promising that Futures from deleteInstanceFn have been resolved, just that we won't make any more calls to deleteInstanceFn.

This requires us to not use scheduleMicrotask(..., but instead do:

Future? f;
try {
  // We've promised to never all deleteInstanceFn after the return
  // from this function! But have not promised to await Futures
  // from deleteInstanceFn in this function!
  f = deleteInstanceFn(...)
} catch (e, st) {
  _log.severe('Failed to delete $instance', e, st);
}
if (f != null) {
  scheduleMicroTask(() async {
    try {
      await f;
    } catch (e, st) {
      _log.severe('Failed to delete $instance', e, st);
    }
  });
}

or something like that.

We should declare the invariant in the documentation comment for scanAndDeleteInstances.

@isoos isoos force-pushed the task-loop-delete-instances branch from 135b26b to c77f148 Compare December 3, 2025 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants